package j04zuoye;
class Person{
    String name;

    public Person(String name) {
        this.name = name;
    }
    void raiseAnimal(Animal animal){
        System.out.println(name+"喂养"+animal.name);
        animal.eat();
        System.out.println("=====");
    }
}
class Animal{
    String name;
    void eat(){
        System.out.println("动物吃食物");
    }

    public Animal() {
    }

    public Animal(String name) {
        this.name = name;
    }
}
class Cat extends Animal{
    void eat() {
        System.out.println(name+"吃鱼");
    }
    void catchMouse(){
        System.out.println(name+"抓老鼠");
    }

    public Cat(String name) {
        super(name);
    }
}
class Bird extends Animal{
    void eat() {
        System.out.println(name+"吃虫子");
    }
    void catchInsects(){
        System.out.println(name+"抓虫子");
    }

    public Bird(String name) {
        super(name);
    }
}
class Dog extends Animal{
    void eat() {
        System.out.println(name+"吃骨头");
    }
    void lookDoor(){
        System.out.println(name+"看门");
    }

    public Dog(String name) {
        super(name);
    }
}


public class Z1TestRaise {
    public static void main(String[] args) {
        Person luxun = new Person("鲁迅");
        luxun.raiseAnimal(new Dog("旺财"));
        luxun.raiseAnimal(new Cat("奶牛"));
        luxun.raiseAnimal(new Bird("鸵鸟"));
        System.out.println(">>>>>>>>>>>>>>");
//        Animal[] arr = new Animal[3];
        Animal[] arr = {
                new Bird("poly"),
                new Bird("鹌鹑"),
                new Cat("加菲猫"),
                new Dog("泰迪"),
                new Bird("鹦鹉")
        };
        for (int i = 0; i < arr.length; i++) {
            Animal a = arr[i];
            if(a instanceof Cat){
//                Cat c0 = (Cat)a;
//                c0.catchMouse();
                ((Cat) a).catchMouse();
            } else if (a instanceof Dog) {
                ((Dog)a).lookDoor();
            }else {
                ((Bird)a).catchInsects();
            }
        }
    }
}
